package com.platform.api.modular.demo.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.api.modular.demo.entity.SysApp;
import com.platform.api.modular.demo.mapper.SysAppMapper;
import com.platform.api.modular.demo.param.DemoParam;
import com.platform.api.modular.demo.result.SysAppResult;
import com.platform.api.modular.demo.service.SysAppService;
import com.platform.core.context.login.LoginContextHolder;
import com.platform.core.enums.CommonStatusEnum;
import com.platform.core.factory.PageFactory;
import com.platform.core.pojo.page.PageResult;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * 系统应用service接口实现类
 */
@Service("sysAppServiceImpl2")
public class SysAppServiceImpl extends ServiceImpl<SysAppMapper, SysApp> implements SysAppService {

    @Override
    public PageResult<SysApp> page(DemoParam sysAppParam) {
        LambdaQueryWrapper<SysApp> queryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtil.isNotNull(sysAppParam)) {
            //根据名称模糊查询
            if (ObjectUtil.isNotEmpty(sysAppParam.getName())) {
                queryWrapper.like(SysApp::getName, sysAppParam.getName());
            }
            //根据编码模糊查询
            if (ObjectUtil.isNotEmpty(sysAppParam.getCode())) {
                queryWrapper.like(SysApp::getCode, sysAppParam.getCode());
            }
        }
        queryWrapper.eq(SysApp::getStatus, CommonStatusEnum.ENABLE.getCode());
        return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper));
    }

    @Override
    public PageResult<SysAppResult> page2(DemoParam sysUserParam) {
        QueryWrapper<SysAppResult> queryWrapper = new QueryWrapper<>();
        return new PageResult<>(this.baseMapper.page(PageFactory.defaultPage(), queryWrapper));

    }

    @Transactional
    @Override
    public void addDemo(DemoParam sysUserParam) {
        SysApp sysApp = new SysApp();
        sysApp.setName("测试新增");
        sysApp.setCode("test001");
        sysApp.setStatus(1);
        this.save(sysApp);

        int i = 10/0;

    }


}
